package com.example.shop.controller;

import com.example.shop.entity.Money;
import com.example.shop.service.MoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName MoneyController
 * @Description TODO
 * @Author zenghw
 * @Date 2025/3/26 10:21
 */

@RestController
@RequestMapping("/api/money")
public class MoneyController {

    @Autowired
    private MoneyService moneyService;

    /**
     * 通过ID查询单条数据
     *
     * @param moneyid 主键
     * @return 实例对象
     */
    @GetMapping("/{moneyid}")
    public Money queryById(@PathVariable("moneyid") Integer moneyid) {
        return moneyService.queryById(moneyid);
    }

    /**
     * 新增数据
     *
     * @param money 实例对象
     * @return 实例对象
     */
    @PostMapping
    public Money insert(@RequestBody Money money) {
        return moneyService.insert(money);
    }

    /**
     * 修改数据
     *
     * @param money 实例对象
     * @return 实例对象
     */
    @PutMapping
    public Money update(@RequestBody Money money) {
        return moneyService.update(money);
    }

    /**
     * 通过主键删除数据
     *
     * @param moneyid 主键
     * @return 是否成功
     */
    @DeleteMapping("/{moneyid}")
    public boolean deleteById(@PathVariable("moneyid") Integer moneyid) {
        return moneyService.deleteById(moneyid);
    }
}
